<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>显示密码和隐藏密码</title>
</head>
<body>
    <input type="password" id="pwd">
    <button id="dsl">显示密码</button>
</body>
<script>
    var pwd = document.getElementById('pwd');
    var dsl = document.getElementById('dsl');
    var flag = 0;
    dsl.onclick = function () {
        if (flag == 0) {
            pwd.type = 'text';
            dsl.innerHTML = '隐藏密码';
            flag = 1;
        } else {
            pwd.type = 'password';
            dsl.innerHTML = '显示密码';
            flag = 0;
        }
    }
</script>
</html>